<template>
	<div>
		<el-dialog title="零碳园区" :visible.sync="dialogVisible" width="60%">

			<el-form ref="form" :model="form" label-width="100px">
				<el-form-item label="园区名称">
					<el-input v-model="form.parkName" placeholder="园区名称"></el-input>
				</el-form-item>
				<el-form-item label="所属区域">
					<el-cascader :options="options" v-model="form.cantonCode" style="width: 100%;"></el-cascader>
				</el-form-item>
				<el-form-item label="计划建设时间">
					<el-date-picker v-model="form.planBuildTime" type="date" placeholder="结束时间" size="mini"
						format="yyyy-MM-dd" value-format="yyyy-MM-dd">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="实际建设时间">
					<el-date-picker v-model="form.actualBuildTime" type="date" placeholder="结束时间" size="mini"
						format="yyyy-MM-dd" value-format="yyyy-MM-dd">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="当前状态">
					<el-select v-model="form.state" placeholder="请选择">
						<el-option label="规划中" value="PLAN" />
						<el-option label="建设中" value="BUILD" />
						<el-option label="建设完成" value="COMPLETE" />
					</el-select>
				</el-form-item>
				<el-form-item label="等级">
					<el-select v-model="form.grade" placeholder="请选择">
						<el-option label="国家级" value="COUNTRY" />
						<el-option label="省级" value="PROVINCE" />
						<el-option label="市级" value="CITY" />
					</el-select>
				</el-form-item>
			</el-form>

			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false,form = $options.data().form">取 消</el-button>
				<el-button type="primary" @click="confirmSave">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		provinceAndCityData,
		regionData,
		pcTextArr,
		pcaTextArr,
		codeToText
	} from 'element-china-area-data'
	let that
	export default {
		name: 'saveTarget',
		data() {
			return {
				form: {
					parkName: '',
					cantonCode: ''
				},
				dialogVisible: false,
				options: regionData,
			}
		},
		mounted() {
			that = this
		},
		methods: {
			open(item){
				that.dialogVisible = true
				if(item){
					that.form = item
				}else{
					that.form = that.$options.data().form
				}
			},
			
			confirmSave() {
				this.$confirm('是否确认保存', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let thisData = JSON.parse((JSON.stringify(that.form)))
					thisData.cantonCode = thisData.cantonCode[thisData.cantonCode.length - 1]
					that.ajax({
						url: '/gov/carbon/park/save',
						data: JSON.stringify(thisData),
						contentType: 'application/json',
						success: function(result) {
							if (result.data) that.dialogVisible = false
							that.form = that.$options.data().form
						}
					})
				})

			},
		},
	}
</script>

<style scoped>

</style>